// 管理所有请求的接口函数
import ajax from './ajax'
import mockAjax from './mockAjax'

export function getCategoryLis() {
  return ajax({
    url: '/product/getBaseCategoryList',
    method: 'get',
  })
}
export function reqBannerList() {
  return mockAjax({
    url: '/banner',
    method: 'get',
  })
}
export function reqFloorList() {
  return mockAjax({
    url: '/floor',
    method: 'get',
  })
}

export const reqSearchInfo = (searchParams) =>
  ajax({ url: '/list', method: 'post', data: searchParams })

// 获取商品详情接口
export const reqGoodsDetailInfo = (skuId) =>
  ajax({ url: `/item/${skuId}`, method: 'get' })

// 添加到购物车或更新购物车数量接口函数
export const reqAddOrUpdateCart = (skuId, skuNum) =>
  ajax({ url: `/cart/addToCart/${skuId}/${skuNum}`, method: 'post' })

// 请求购物车的接口函数
export const reqShopcartList = () =>
  ajax({ url: '/cart/cartList', method: 'get' })

// 请求修改单选框的接口函数
export const reqChangeChecked = (skuId, isChecked) =>
  ajax({ url: `/cart/checkCart/${skuId}/${isChecked}`, method: 'get' })

// 请求修改全选框的接口函数
export const reqAllChecked = (isChecked, skuIdList) =>
  ajax({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: 'post',
    data: skuIdList,
  })

// 请求删除某一项商品的接口函数
export const deleteShopCart = (skuId) =>
  ajax({
    url: `/cart/deleteCart/${skuId}`,
    method: 'delete',
  })

// 请求删除已选中商品的接口函数
export const deleteChooseCart = (skuIdList) =>
  ajax({
    url: `/cart/batchDeleteCart`,
    method: 'post',
    data: skuIdList,
  })

// 请求用户注册的接口函数
export const reqUserRegister = (userInfo) =>
  ajax({ url: '/user/passport/register', method: 'post', data: userInfo })

// 请求验证码的接口函数
export const reqCode = (phone) =>
  ajax({ url: `/user/passport/sendCode/${phone}`, method: 'get' })

// 请求登录的接口函数
export const reqLogin = (userInfo) =>
  ajax({ url: '/user/passport/login', method: 'post', data: userInfo })

// 请求用户信息的接口函数
export const reqUserInfo = () =>
  ajax({ url: '/user/passport/auth/getUserInfo', method: 'get' })
